package com.stu.service.base;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;

import com.stu.entity.base.BaseEntity;

/**
 * service 基类
 * @author lijian
 *
 * @param <T> PO
 */
public interface IBaseService<T extends BaseEntity> {
	
	/**
	 * 保存一个对象
	 * @param t
	 * @return id
	 * @
	 */
	public Serializable save(T t) throws SQLException;
	
	/**
	 * 批量保存
	 * @author lijian
	 *
	 * @param list
	 * @throws SQLException
	 */
	public void saveBatch(List<? extends BaseEntity> list) throws SQLException;
	
	/**
	 * 删除一个对象
	 * @param o
	 * @return
	 * @
	 */
	public boolean delete(T o);
	/**
	 * 删除集合
	 * @param ids 
	 * 			格式 1,2,3
	 * @return
	 * @
	 */
	public boolean deleteIds(String ids) throws SQLException ;
	/**
	 * 更新一个对象
	 * @param o
	 * @return
	 * @
	 */
	public boolean update(T o) throws SQLException;
	/**
	 * 更新一个对象， 
	 * @param o
	 * @param except 要排除的属性集合
	 * @return
	 * @
	 */
	public boolean update(T o, List<String> except) throws SQLException;
	
	/**
	 * 通过ID 查询
	 * @param id
	 * @return
	 * @
	 */
	public T findById(String id) throws SQLException;
	/**
	 * 
	 * @author lijian
	 *
	 * @param c
	 * @param id
	 * @return
	 */
	public T findById(Class<?> c, Serializable id) throws SQLException;

	/**
	 * 
	 * @author lijian
	 *
	 * @param hql
	 * @return
	 */
	public T findByHql(String hql) throws SQLException;
	/**
	 * 
	 * @author lijian
	 *
	 * @param hql
	 * @param params
	 * @return
	 */
	public T findByHql(String hql, Map<String, Object> params) throws SQLException;
	/**
	 * 查询所有数据
	 * @return
	 * @
	 */
	public List<T> find() throws SQLException;
	/**
	 * 查询
	 * @param page 当前页
	 * @param rows 煤业记录数
	 * @return
	 * @
	 */
	public List<T> find(int page,int rows) throws SQLException ;
	/**
	 * 查询
	 * @param hql 
	 * @return
	 * @
	 */
	public List<T> find(String hql) throws SQLException;
	/**
	 * 查询
	 * @param hql
	 * @param params 参数
	 * @return
	 * @
	 */
	public List<T> find(String hql, Map<String, Object> params) throws SQLException;
	/**
	 * 查询
	 * @param hql
	 * @param params 参数
	 * @param page 当前页
	 * @param rows 每页记录数
	 * @return
	 * @
	 */
	public List<T> find(String hql, Map<String, Object> params, int page, int rows) throws SQLException ;
	/**
	 * 
	 * @author lijian
	 *
	 * @param sql
	 * @param params
	 * @param page
	 * @param rows
	 * @param clazz
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<T> findBySqlToBean(String sql, Map<String, Object> params, int page, int rows,Class<T> clazz) throws HibernateException, SQLException ;
	/**
	 * 
	 * @author lijian
	 *
	 * @param sql
	 * @param params
	 * @param page
	 * @param rows
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<T> findBySqlToBean(String sql, Map<String, Object> params, int page, int rows) throws HibernateException, SQLException ;
	

	/**
	 * 
	 * @author lijian
	 *
	 * @param sql
	 * @return
	 * @throws HibernateException
	 * @
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql) throws SQLException;

	/**
	 * 
	 * @author lijian
	 *
	 * @param sql
	 * @param page
	 * @param rows
	 * @return
	 * @throws HibernateException
	 * @
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql, int page, int rows) throws SQLException;
	
	/**
	 * 
	 * @author lijian
	 *
	 * @param sql
	 * @param params
	 * @return
	 * @throws HibernateException
	 * @
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql, Map<String, Object> params) throws SQLException;
	
	/**
	 * 
	 * @author lijian
	 *
	 * @param sql
	 * @param params
	 * @param page
	 * @param rows
	 * @return
	 * @throws HibernateException
	 * @
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql, Map<String, Object> params, int page, int rows) throws SQLException ;

	/**
	 * 查询记录数
	 * @return
	 * @
	 */
	public int count() throws SQLException ;
	/**
	 * 查询记录数
	 * @param hql
	 * @return
	 * @
	 */
	public int count(String hql) throws SQLException ;
	/**
	 * 查询记录数
	 * @param hql
	 * @param params 参数
	 * @return
	 * @
	 */
	public int count(String hql, Map<String, Object> params) throws SQLException;
	/**
	 * 查询记录数
	 * @param sql
	 * @return
	 * @
	 */
	public int countBySql(String sql) throws SQLException;
	
	/**
	 * 执行sql 语句
	 * @param sql
	 * @return
	 * @
	 */
	public int executeSql(String sql) throws SQLException;

	/**
	 * 执行sql 语句
	 * @param sql
	 * @param params 参数
	 * @return
	 * @
	 */
	public int executeSql(String sql, Map<String, Object> params) throws SQLException ;
	/**
	 * 执行hql 语句
	 * @param hql
	 * @return
	 * @
	 */
	public int executeHql(String hql) throws SQLException;
	/**
	 * 执行hql 语句
	 * @param hql
	 * @param params 参数
	 * @return
	 * @
	 */
	public int executeHql(String hql, Map<String, Object> params)throws SQLException ;

}
